#include<bits/stdc++.h>
using namespace std;
int L, N;
// priority_queue<pair<int, int>, vector<pair<int, int>>, less<pair<int, int>>> pq;
vector<pair<int, int> > vec;
map<int, int> mp; 

bool cmp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

void add(int postion, int value) {
    if (mp.find(postion) != mp.end()) {
        for (int i = 0; i < vec.size(); i++) {
            if (vec[i].first == postion) {
                vec[i].second = value;
                break;
            }
        }
    } else {
        pair<int, int> p(postion, value);
        vec.push_back(p);
    }
    mp[postion] = value;
}

void sout(int start, int end) {
    vector<pair<int, int> > temp;
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i].first <= end && vec[i].first >= start) 
            temp.push_back(vec[i]);
    }
    if (temp.size() < 8) {
        cout << 0 << endl;
        return;
    }
    sort(temp.begin(), temp.end(), cmp);
    cout << temp[7].second << endl;
}

int main() {
    cin >> L >> N;
    while (N--) {
        char op;
        int a, b;
        cin >> op >> a >> b;
        if (op == 'C') add(a, b);
        else sout(a, b);
    }
    return 0;
}

/*
10 15
C 1 10
C 2 20
C 3 30
C 4 40
C 5 50
C 6 60
C 7 70
C 8 80
C 9 90
C 10 100
Q 1 2
Q 1 10
Q 1 8
C 10 1
Q 1 10
*/